// const baseurl = 'http://192.168.5.1'
const baseurl = window.location.origin
console.log(baseurl)
const COM_CONSTANT = {
  POST_DEVICE_REQUEST_URL: `${baseurl}/device_request`,
}


var Ajax = {
  get: function(url,callback){
    // XMLHttpRequest对象用于在后台与服务器交换数据
    console.log('456789')
    var xhr=new XMLHttpRequest();
    xhr.open('GET', url,false);
    xhr.setRequestHeader('Content-Type','application/json');
    xhr.onreadystatechange=function(){
      if(xhr.readyState === 4){
        if(xhr.status === 200 || xhr.status === 304){
          console.log(xhr.responseText);
          callback(xhr.responseText);
        } else {
          console.log(xhr.responseText);
        }
      }
    }
    xhr.send();
  },
  put: function(url, data, callback) {
    var xhr=new XMLHttpRequest();
    xhr.open('put', url,false);
    xhr.setRequestHeader('Content-Type','application/json');
    xhr.onreadystatechange=function(){
      if(xhr.readyState === 4){
        if(xhr.status === 200 || xhr.status === 304){
          console.log(xhr.responseText);
          callback(xhr.responseText);
        } else {
          console.log(xhr.responseText);
        }
      }
    }
    xhr.send(JSON.stringify(data));
  },
  post: function(url, data, callback){
    var xhr=new XMLHttpRequest();
    xhr.open('POST', url,false);
    // 添加http头，发送信息至服务器时内容编码类型
    xhr.setRequestHeader('Content-Type','application/json');
    xhr.onreadystatechange=function(){
      console.log('1: ', xhr.readyState)
      console.log('2: ', xhr.status)
      console.log('3: ', xhr.responseText)
      if (xhr.readyState === 4){
        if (xhr.status === 200 || xhr.status === 304){
          callback(xhr.responseText);
        }
      }
    }
    xhr.send(JSON.stringify(data));
  },
  postFile: function(e, g, h) {
    // showLoading();
    var f;
    if (window.XMLHttpRequest) {
        f = new XMLHttpRequest()
    } else {
        if (window.ActiveObject) {
            f = new ActiveXobject("Microsoft.XMLHTTP")
        }
    }
    f.open("POST", e, false);
    f.setRequestHeader("Content-Type",
        "application/octet-stream;charset=UTF-8");
    f.onreadystatechange = function() {
        if (f.readyState == 4) {
            if (f.status == 200 || f.status ==
                304) {
                h.call(this, f.responseText)
            } else {
                // hideLoading("msg-load");
                alert("升级失败，请稍后重试");
            }
        }
    };
    f.send(g)
  },
  postDeviceRequest: function(e, g, h) {
    // showLoading();
    var f;
    if (window.XMLHttpRequest) {
        f = new XMLHttpRequest()
    } else {
        if (window.ActiveObject) {
            f = new ActiveXobject("Microsoft.XMLHTTP")
        }
    }
    f.open("POST", e, false);
    f.setRequestHeader("Content-Type",
        "application/json"
    );
    f.setRequestHeader("Mesh-Node-Mac",
        "ffffffffffff"
    );
    f.onreadystatechange = function() {
        if (f.readyState == 4) {
            if (f.status == 200 || f.status ==
                304) {
                h.call(this, f.responseText)
            } else {
              console.log("requestFailed", f.responseText)
            }
        }
    };
    f.send(g)
  },
}

function selectTitle(a) {
  var baseArray1 = document.getElementsByClassName('header-title-one')
  for (var i = 0; i < baseArray1.length; i++) {
    // baseArray1[i].classList.remove('header-title-one-active')
    baseArray1[i].style.color = '#000'
    baseArray1[i].style.cursor = 'pointer'
  }
  // a.classList.add('header-title-one-active')
  a.style.color = '#0089FF'
  a.style.cursor = 'auto'
}

function selectContent(a) {
  var baseArray = document.getElementsByClassName('page-content')
  
  for (var i = 0; i < baseArray.length; i++) {
    baseArray[i].style.display = 'none'
  }
  var show = document.getElementById(a)
  show.style.display = 'block'
}

function menuClick (e) {
  console.log('e: ', e.classList)
  var menuView = document.getElementById('leftMenu')
  if (e.classList.contains('delMenu')) {
    menuView.style.display = 'none'
    e.classList.remove('delMenu')
  } else {
    e.classList.add('delMenu')
    menuView.style.display = 'block'
  }

}
